<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title></title>
    <link rel="stylesheet" type="text/css" href="statics/css/login.css">
</head>
<body>
<div id="wrapper" class="login-page">
    <div id="" class="form">
        <form class="login-form">
            <h2>用户注册</h2>
            <div><input type="text" placeholder="用户名" id="r_user_name" name="username"/></div>
            <div><input type="password" placeholder="密码" id="r_password" name="password"/></div>
            <div><input type="password" placeholder="确认密码" id="r_password_again" name="passwordSure"/></div>
            <div><input type="text" placeholder="邮箱" id="r_email" name="email"/></div>
            <div><input type="text" placeholder="手机号" id="r_phone" name="phone"/></div>
            <div><input type="text" placeholder="学号" id="r_user_no" name="userNo"/></div>
            <div>
                <input type="button" onclick="check_register()" value="创建账户" style="background: #0dc316"/>
            </div>
            <p class="message" >已经有了一个账户? <a onclick="login()">立刻登录</a></p>
        </form>
    </div>
</div>
<script src="statics/lib/layui/layui.js" charset="utf-8"></script>
<script src="statics/js/jquery.min.js"></script>
<script type="text/javascript">
    var layer;
    layui.use('layer', function () {
        layer = layui.layer;
    });

    function check_register() {
        var registerInfo = $(".login-form").serialize();
        registerInfo= decodeURIComponent(registerInfo,true);
        var json =strToJson(registerInfo);
        debugger;
        $.ajax({
            type:"POST",
            url:"user/register",
            data:json,
            success:function (result) {
                if(0==result.code){
                    layer.msg(result.msg,{icon: 1, time: 1000});
                }else{
                    layer.msg(result.msg,{icon: 5, time: 1000});
                }
            },
            error:function () {
                layer.msg("注册失败",{icon: 5, time: 1000});
            }
        })
    }
    function login() {
        window.location.href = "/user/doLogin";
    }
    function strToJson(data){
        data=data.replace(/&/g,"\",\"");
        data=data.replace(/=/g,"\":\"");
        data="({\""+data+"\"})";
        var obj = eval(data);
        return obj;
    }


</script>
</body>
</html>